package src.com.hpu.parser;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import com.hpu.bean.Score;

/**
 * 期末成绩解析器
 * 
 * @author Administrator
 * 
 */
public class AllScoreParser {

	public List<List<Score>> parse(String parseString) {
		List<List<Score>> scoreList = new ArrayList<>();
		try {
			JSONArray array = new JSONArray(parseString);
			String[] termArray = { "大一上", "大一下", "大二上", "大二下", "大三上", "大三下", "大四上", "大四下" };
			int termLength = termArray.length;
			for (int i = 0; i < array.length(); i++) {
				JSONArray array2 = array.getJSONArray(i);
				String term = termLength >= i ? termArray[i] : "未知学期";
				List<Score> scores = new ArrayList<>();
				for (int j = 0; j < array2.length(); j++) {
					JSONArray array3 = array2.getJSONArray(j);
					String credit = array3.getString(4);
					String subject = array3.getString(2);
					String number = array3.getString(0);
					String order = array3.getString(1);
					String value = array3.getString(6).length() == 0 ? "--" : array3.getString(6);
					String  valueOrder="--";
					scores.add(new Score(credit, subject, term, number, order, value,valueOrder));
				}
				scoreList.add(scores);
			}

		} catch (JSONException e) {
			e.printStackTrace();
		}
		return scoreList;
	}

}
